/* Project: POPS
 * CS 279, Vanderbilt University
 * by: Igor I. Ges, Michael S. Parrish, Mark E. Sakauye
 *
 *  This program is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *   (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package com.popsGUI.java;

import java.awt.Component;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.print.PageFormat;
import java.awt.print.Printable;
import java.awt.print.PrinterException;
import java.awt.print.PrinterJob;
import java.text.DateFormat;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.Random;

import javax.swing.RepaintManager;

import com.popsDB.java.dto.Customers;
import com.popsDB.java.dto.CustomersPk;
import com.popsDB.java.dto.Employee;
import com.popsDB.java.dto.Items;
import com.popsDB.java.dto.Pricesheets;

//import com.popsDB.java.dao.CustomersDao;
//import com.popsDB.java.dao.ItemsDao;
//import com.popsDB.java.dao.OrdereditemsDao;
//import com.popsDB.java.dao.OrdersDao;
//import com.popsDB.java.factory.CustomersDaoFactory;
//import com.popsDB.java.factory.ItemsDaoFactory;
//import com.popsDB.java.factory.OrdereditemsDaoFactory;
//import com.popsDB.java.factory.OrdersDaoFactory;

/**
 *
 * @author  __USER__
 */
public class CustomerPanel extends javax.swing.JPanel implements Printable {

	///////////// Final Variable Declarations /////////
	final int ZIP_LENGTH_MIN = 5;
	final int ZIP_LENGTH_MAX = 10;
	final int PHONE_LENGTH_MIN = 7;
	final int PHONE_LENGTH_MAX = 14;
	final int INTERVAL_LENGTH_MIN = 2;
	final int INTERVAL_LENGTH_MAX = 3;

	final String SELECT_FOREMAN = "Select a Foreman Code...";
	final String SELECT_EXTERNAL_SALESPERSON = "Select an External Salesperson Code...";
	final String SELECT_SALESPERSON = "Select a Salesperson Code...";
	final String SELECT_CUSTID = "Select a Bill-To-Customer ID...";
	final String SELECT_PRICE_SHEET = "Select a Price Sheet...";
	final String SELECT_PRICE_GROUP = "Select a Price Group...";
	final String DEFAULT_BILL_TO_ID = "Bill-To Self";

	/////////// End Final Variable Declarations /////////

	/** Creates new form CustomerPanel */
	public CustomerPanel() {
		initComponents();
		com.popsGUI.java.notificationDialog notificationDialog = 
			new com.popsGUI.java.notificationDialog(null,false);
	}

	/** This method is called from within the constructor to
	 * initialize the form.
	 * WARNING: Do NOT modify this code. The content of this method is
	 * always regenerated by the Form Editor.
	 */
	//GEN-BEGIN:initComponents
	// <editor-fold defaultstate="collapsed" desc="Generated Code">
	private void initComponents() {

		fieldsFail = new javax.swing.JDialog();
		OK = new javax.swing.JButton();
		message = new javax.swing.JLabel();
		message2 = new javax.swing.JLabel();
		selectCust_dialog_CUSTOMER = new javax.swing.JDialog();
		selectCust_dialog_CUSTOMER_combobox = new javax.swing.JComboBox();
		selectCust_dialog_CUSTOMER_label = new javax.swing.JLabel();
		selectCust_dialog_CUSTOMER_button = new javax.swing.JButton();
		selectCust_dialog_CUSTOMER_error = new javax.swing.JLabel();
		custChangesSaved_dialog = new javax.swing.JDialog();
		ccs_label = new javax.swing.JLabel();
		ccs_ok_button = new javax.swing.JButton();
		cp_custID_label = new javax.swing.JLabel();
		cp_custID_field = new javax.swing.JLabel();
		cp_name_label = new javax.swing.JLabel();
		cp_name_field = new javax.swing.JTextField();
		cp_address_label = new javax.swing.JLabel();
		cp_address_field1 = new javax.swing.JTextField();
		cp_address_field2 = new javax.swing.JTextField();
		cp_city_label = new javax.swing.JLabel();
		cp_city_field = new javax.swing.JTextField();
		cp_state_label = new javax.swing.JLabel();
		cp_state_field = new javax.swing.JTextField();
		cp_zipcode_label = new javax.swing.JLabel();
		cp_zipcode_field = new javax.swing.JTextField();
		cp_priceSheet_label = new javax.swing.JLabel();
		cp_priceSheet_combobox = new javax.swing.JComboBox();
		cp_directions_label = new javax.swing.JLabel();
		jScrollPane5 = new javax.swing.JScrollPane();
		cp_directions_field = new javax.swing.JTextArea();
		cp_phoneNum_label1 = new javax.swing.JLabel();
		cp_phoneNum_label2 = new javax.swing.JLabel();
		cp_faxNum_label = new javax.swing.JLabel();
		cp_phoneNum_field1 = new javax.swing.JTextField();
		cp_phoneNum_field2 = new javax.swing.JTextField();
		cp_faxNum_field = new javax.swing.JTextField();
		cp_foreman_label = new javax.swing.JLabel();
		cp_extSalespersonCode_label = new javax.swing.JLabel();
		cp_salesmanCode_label = new javax.swing.JLabel();
		cp_foreman_combobox = new javax.swing.JComboBox();
		cp_extSalespersonCode_combobox = new javax.swing.JComboBox();
		cp_salesmanCode_combobox = new javax.swing.JComboBox();
		cp_interval_label = new javax.swing.JLabel();
		cp_priceSheetTemplate_label = new javax.swing.JLabel();
		cp_priceSheetTemplate_combobox = new javax.swing.JComboBox();
		cp_printPriceSheet_label = new javax.swing.JLabel();
		cp_printPriceSheet_field = new javax.swing.JLabel();
		cp_paymentTermsCode_label = new javax.swing.JLabel();
		cp_paymentTermsCode_combobox = new javax.swing.JComboBox();
		cp_eachSheetCode_label = new javax.swing.JLabel();
		cp_eachSheetCode_combobox = new javax.swing.JComboBox();
		cp_marriett_label = new javax.swing.JLabel();
		cp_marriett_field = new javax.swing.JLabel();
		cp_accountRep_label = new javax.swing.JLabel();
		cp_accountRep_field = new javax.swing.JTextField();
		cp_billToCustID_label = new javax.swing.JLabel();
		cp_billToCustID_combobox = new javax.swing.JComboBox();
		cp_financeChargeCode_label = new javax.swing.JLabel();
		cp_printStatements_label = new javax.swing.JLabel();
		cp_taxLiable_label = new javax.swing.JLabel();
		cp_taxLiable_checkbox = new javax.swing.JCheckBox();
		cp_taxExemptionCode_label = new javax.swing.JLabel();
		cp_taxAreaCode_label = new javax.swing.JLabel();
		cp_financeChargeCode_combobox = new javax.swing.JComboBox();
		cp_printStatements_checkbox = new javax.swing.JCheckBox();
		cp_taxExemptionCode_combobox = new javax.swing.JComboBox();
		cp_taxAreaCode_combobox = new javax.swing.JComboBox();
		cp_custStatus_label = new javax.swing.JLabel();
		cp_custStatus_field = new javax.swing.JLabel();
		cp_saveCustChanges_button = new javax.swing.JButton();
		cp_custActivation_button = new javax.swing.JButton();
		cp_selectCustomer_button = new javax.swing.JButton();
		cp_interval_field = new javax.swing.JTextField();
		cp_print_button = new javax.swing.JButton();

		fieldsFail.setMinimumSize(new java.awt.Dimension(350, 300));

		OK.setText("OK");
		OK.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				OKActionPerformed(evt);
			}
		});

		message.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
		message.setText("All fields are not entered correctly.");
		message.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);

		message2.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);

		javax.swing.GroupLayout fieldsFailLayout = new javax.swing.GroupLayout(
				fieldsFail.getContentPane());
		fieldsFail.getContentPane().setLayout(fieldsFailLayout);
		fieldsFailLayout
				.setHorizontalGroup(fieldsFailLayout
						.createParallelGroup(
								javax.swing.GroupLayout.Alignment.LEADING)
						.addGroup(
								fieldsFailLayout
										.createSequentialGroup()
										.addContainerGap()
										.addComponent(
												message,
												javax.swing.GroupLayout.DEFAULT_SIZE,
												330, Short.MAX_VALUE)
										.addContainerGap())
						.addGroup(
								fieldsFailLayout
										.createSequentialGroup()
										.addGap(100, 100, 100)
										.addComponent(
												OK,
												javax.swing.GroupLayout.DEFAULT_SIZE,
												147, Short.MAX_VALUE).addGap(
												103, 103, 103))
						.addGroup(
								fieldsFailLayout
										.createSequentialGroup()
										.addContainerGap()
										.addComponent(
												message2,
												javax.swing.GroupLayout.DEFAULT_SIZE,
												330, Short.MAX_VALUE)
										.addContainerGap()));
		fieldsFailLayout
				.setVerticalGroup(fieldsFailLayout
						.createParallelGroup(
								javax.swing.GroupLayout.Alignment.LEADING)
						.addGroup(
								fieldsFailLayout
										.createSequentialGroup()
										.addGap(21, 21, 21)
										.addComponent(message)
										.addGap(18, 18, 18)
										.addComponent(
												message2,
												javax.swing.GroupLayout.DEFAULT_SIZE,
												150, Short.MAX_VALUE)
										.addPreferredGap(
												javax.swing.LayoutStyle.ComponentPlacement.RELATED)
										.addComponent(OK).addContainerGap()));

		selectCust_dialog_CUSTOMER.setMinimumSize(new java.awt.Dimension(350,
				210));

		selectCust_dialog_CUSTOMER_label
				.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
		selectCust_dialog_CUSTOMER_label.setText("Select Customer");

		selectCust_dialog_CUSTOMER_button.setText("OK");
		selectCust_dialog_CUSTOMER_button
				.addActionListener(new java.awt.event.ActionListener() {
					public void actionPerformed(java.awt.event.ActionEvent evt) {
						selectCust_dialog_CUSTOMER_buttonActionPerformed(evt);
					}
				});

		javax.swing.GroupLayout selectCust_dialog_CUSTOMERLayout = new javax.swing.GroupLayout(
				selectCust_dialog_CUSTOMER.getContentPane());
		selectCust_dialog_CUSTOMER.getContentPane().setLayout(
				selectCust_dialog_CUSTOMERLayout);
		selectCust_dialog_CUSTOMERLayout
				.setHorizontalGroup(selectCust_dialog_CUSTOMERLayout
						.createParallelGroup(
								javax.swing.GroupLayout.Alignment.LEADING)
						.addGroup(
								selectCust_dialog_CUSTOMERLayout
										.createSequentialGroup()
										.addGroup(
												selectCust_dialog_CUSTOMERLayout
														.createParallelGroup(
																javax.swing.GroupLayout.Alignment.LEADING)
														.addGroup(
																selectCust_dialog_CUSTOMERLayout
																		.createSequentialGroup()
																		.addGap(
																				52,
																				52,
																				52)
																		.addGroup(
																				selectCust_dialog_CUSTOMERLayout
																						.createParallelGroup(
																								javax.swing.GroupLayout.Alignment.LEADING,
																								false)
																						.addComponent(
																								selectCust_dialog_CUSTOMER_label,
																								javax.swing.GroupLayout.DEFAULT_SIZE,
																								javax.swing.GroupLayout.DEFAULT_SIZE,
																								Short.MAX_VALUE)
																						.addComponent(
																								selectCust_dialog_CUSTOMER_combobox,
																								0,
																								227,
																								Short.MAX_VALUE)))
														.addGroup(
																selectCust_dialog_CUSTOMERLayout
																		.createSequentialGroup()
																		.addGap(
																				146,
																				146,
																				146)
																		.addComponent(
																				selectCust_dialog_CUSTOMER_button))
														.addGroup(
																javax.swing.GroupLayout.Alignment.TRAILING,
																selectCust_dialog_CUSTOMERLayout
																		.createSequentialGroup()
																		.addContainerGap()
																		.addComponent(
																				selectCust_dialog_CUSTOMER_error,
																				javax.swing.GroupLayout.DEFAULT_SIZE,
																				316,
																				Short.MAX_VALUE)))
										.addContainerGap()));
		selectCust_dialog_CUSTOMERLayout
				.setVerticalGroup(selectCust_dialog_CUSTOMERLayout
						.createParallelGroup(
								javax.swing.GroupLayout.Alignment.LEADING)
						.addGroup(
								selectCust_dialog_CUSTOMERLayout
										.createSequentialGroup()
										.addGap(38, 38, 38)
										.addComponent(
												selectCust_dialog_CUSTOMER_label)
										.addPreferredGap(
												javax.swing.LayoutStyle.ComponentPlacement.RELATED)
										.addComponent(
												selectCust_dialog_CUSTOMER_combobox)
										.addGap(18, 18, 18)
										.addComponent(
												selectCust_dialog_CUSTOMER_error,
												javax.swing.GroupLayout.PREFERRED_SIZE,
												29,
												javax.swing.GroupLayout.PREFERRED_SIZE)
										.addPreferredGap(
												javax.swing.LayoutStyle.ComponentPlacement.RELATED)
										.addComponent(
												selectCust_dialog_CUSTOMER_button)
										.addGap(34, 34, 34)));

		custChangesSaved_dialog
				.setMinimumSize(new java.awt.Dimension(300, 180));

		ccs_label.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
		ccs_label.setText("Customer changes have been saved!");

		ccs_ok_button.setText("OK");
		ccs_ok_button.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				ccs_ok_buttonActionPerformed(evt);
			}
		});

		javax.swing.GroupLayout custChangesSaved_dialogLayout = new javax.swing.GroupLayout(
				custChangesSaved_dialog.getContentPane());
		custChangesSaved_dialog.getContentPane().setLayout(
				custChangesSaved_dialogLayout);
		custChangesSaved_dialogLayout
				.setHorizontalGroup(custChangesSaved_dialogLayout
						.createParallelGroup(
								javax.swing.GroupLayout.Alignment.LEADING)
						.addGroup(
								custChangesSaved_dialogLayout
										.createSequentialGroup()
										.addGroup(
												custChangesSaved_dialogLayout
														.createParallelGroup(
																javax.swing.GroupLayout.Alignment.LEADING)
														.addGroup(
																custChangesSaved_dialogLayout
																		.createSequentialGroup()
																		.addGap(
																				128,
																				128,
																				128)
																		.addComponent(
																				ccs_ok_button))
														.addGroup(
																custChangesSaved_dialogLayout
																		.createSequentialGroup()
																		.addContainerGap()
																		.addComponent(
																				ccs_label,
																				javax.swing.GroupLayout.DEFAULT_SIZE,
																				276,
																				Short.MAX_VALUE)))
										.addContainerGap()));
		custChangesSaved_dialogLayout
				.setVerticalGroup(custChangesSaved_dialogLayout
						.createParallelGroup(
								javax.swing.GroupLayout.Alignment.LEADING)
						.addGroup(
								javax.swing.GroupLayout.Alignment.TRAILING,
								custChangesSaved_dialogLayout
										.createSequentialGroup()
										.addGap(42, 42, 42)
										.addComponent(ccs_label)
										.addPreferredGap(
												javax.swing.LayoutStyle.ComponentPlacement.RELATED,
												90, Short.MAX_VALUE)
										.addComponent(ccs_ok_button)
										.addContainerGap()));

		setPreferredSize(new java.awt.Dimension(1024, 679));

		cp_custID_label.setText("Customer ID:");

		cp_custID_field.setText("000000");

		cp_name_label.setText("Name:");

		cp_name_field.setText("Name");
		cp_name_field.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				cp_name_fieldActionPerformed(evt);
			}
		});
		cp_name_field.addFocusListener(new java.awt.event.FocusAdapter() {
			public void focusGained(java.awt.event.FocusEvent evt) {
				cp_name_fieldFocusGained(evt);
			}
		});

		cp_address_label.setText("Address:");

		cp_address_field1.setText("Address Line 1");
		cp_address_field1.addFocusListener(new java.awt.event.FocusAdapter() {
			public void focusGained(java.awt.event.FocusEvent evt) {
				cp_address_field1FocusGained(evt);
			}
		});

		cp_address_field2.setText("Address Line 2");
		cp_address_field2.addFocusListener(new java.awt.event.FocusAdapter() {
			public void focusGained(java.awt.event.FocusEvent evt) {
				cp_address_field2FocusGained(evt);
			}
		});

		cp_city_label.setText("City:");

		cp_city_field.setText("City");
		cp_city_field.addFocusListener(new java.awt.event.FocusAdapter() {
			public void focusGained(java.awt.event.FocusEvent evt) {
				cp_city_fieldFocusGained(evt);
			}
		});

		cp_state_label.setText("State:");

		cp_state_field.setText("State");
		cp_state_field.addFocusListener(new java.awt.event.FocusAdapter() {
			public void focusGained(java.awt.event.FocusEvent evt) {
				cp_state_fieldFocusGained(evt);
			}
		});

		cp_zipcode_label.setText("ZIP Code:");

		cp_zipcode_field.setText("Zip");
		cp_zipcode_field.addFocusListener(new java.awt.event.FocusAdapter() {
			public void focusGained(java.awt.event.FocusEvent evt) {
				cp_zipcode_fieldFocusGained(evt);
			}
		});

		cp_priceSheet_label.setText("Price Sheet:");

		cp_priceSheet_combobox.setModel(new javax.swing.DefaultComboBoxModel(
				new String[] { "Contact 1", "Contact 2", "Contact 3" }));

		cp_directions_label.setText("Directions:");

		cp_directions_field.setColumns(20);
		cp_directions_field.setRows(5);
		jScrollPane5.setViewportView(cp_directions_field);

		cp_phoneNum_label1.setText("Phone Number 1:");
		cp_phoneNum_label1.setToolTipText("e.g. 1234567890");

		cp_phoneNum_label2.setText("Phone Number 2:");
		cp_phoneNum_label2.setToolTipText("e.g. 1234567890");

		cp_faxNum_label.setText("Fax Number:");
		cp_faxNum_label.setToolTipText("e.g. 1234567890");

		cp_phoneNum_field1.setText("Phone Number 1");
		cp_phoneNum_field1.setToolTipText("e.g. 1234567890");
		cp_phoneNum_field1.addFocusListener(new java.awt.event.FocusAdapter() {
			public void focusGained(java.awt.event.FocusEvent evt) {
				cp_phoneNum_field1FocusGained(evt);
			}
		});

		cp_phoneNum_field2.setText("Phone Number 2");
		cp_phoneNum_field2.setToolTipText("e.g. 1234567890");
		cp_phoneNum_field2.addFocusListener(new java.awt.event.FocusAdapter() {
			public void focusGained(java.awt.event.FocusEvent evt) {
				cp_phoneNum_field2FocusGained(evt);
			}
		});

		cp_faxNum_field.setText("Fax Number");
		cp_faxNum_field.setToolTipText("e.g. 1234567890");
		cp_faxNum_field.addFocusListener(new java.awt.event.FocusAdapter() {
			public void focusGained(java.awt.event.FocusEvent evt) {
				cp_faxNum_fieldFocusGained(evt);
			}
		});

		cp_foreman_label.setText("Foreman:");

		cp_extSalespersonCode_label.setText("External Salesperson Code:");

		cp_salesmanCode_label.setText("Salesperson Code:");

		cp_foreman_combobox.setModel(new javax.swing.DefaultComboBoxModel(
				new String[] { "Foreman 1", "Foreman 2", "Foreman 3" }));

		cp_extSalespersonCode_combobox
				.setModel(new javax.swing.DefaultComboBoxModel(new String[] {
						"Code 1", "Code 2", "Code 3" }));

		cp_salesmanCode_combobox.setModel(new javax.swing.DefaultComboBoxModel(
				new String[] { "Code 1", "Code 2", "Code 3" }));

		cp_interval_label.setText("Prior Sales Interval:");

		cp_priceSheetTemplate_label.setText("Price Sheet Template:");

		cp_priceSheetTemplate_combobox
				.setModel(new javax.swing.DefaultComboBoxModel(new String[] {
						"Code 1", "Code 2", "Code 3" }));

		cp_printPriceSheet_label.setText("Print Price Sheet:");

		cp_printPriceSheet_field.setText("label");

		cp_paymentTermsCode_label.setText("Payment Terms Code:");

		cp_paymentTermsCode_combobox
				.setModel(new javax.swing.DefaultComboBoxModel(new String[] {
						"Code 1", "Code 2", "Code 3" }));

		cp_eachSheetCode_label.setText("Each Sheet Code:");

		cp_eachSheetCode_combobox
				.setModel(new javax.swing.DefaultComboBoxModel(new String[] {
						"Code 1", "Code 2", "Code 3" }));

		cp_marriett_label.setText("Marriett Account:");

		cp_marriett_field.setText("Stuff");

		cp_accountRep_label.setText("Account Representative:");

		cp_accountRep_field.setText("Rep Name");
		cp_accountRep_field.addFocusListener(new java.awt.event.FocusAdapter() {
			public void focusGained(java.awt.event.FocusEvent evt) {
				cp_accountRep_fieldFocusGained(evt);
			}
		});

		cp_billToCustID_label.setText("Bill-To Customer ID:");

		cp_billToCustID_combobox.setModel(new javax.swing.DefaultComboBoxModel(
				new String[] { "0", "1", "2", "3", "4", "5" }));

		cp_financeChargeCode_label.setText("Finance Charge Code");

		cp_printStatements_label.setText("Print Statements:");

		cp_taxLiable_label.setText("Tax Liable:");

		cp_taxExemptionCode_label.setText("Tax Exemption Code:");

		cp_taxAreaCode_label.setText("Tax Area Code:");

		cp_financeChargeCode_combobox
				.setModel(new javax.swing.DefaultComboBoxModel(new String[] {
						"Code 1", "Code 2", "Code 3" }));

		cp_taxExemptionCode_combobox
				.setModel(new javax.swing.DefaultComboBoxModel(new String[] {
						"Code 1", "Code 2", "Code 3" }));

		cp_taxAreaCode_combobox.setModel(new javax.swing.DefaultComboBoxModel(
				new String[] { "Code 1", "Code 2", "Code 3" }));

		cp_custStatus_label.setText("Customer Status:");

		cp_custStatus_field.setText("Active");

		cp_saveCustChanges_button.setText("Save Changes");
		cp_saveCustChanges_button
				.addActionListener(new java.awt.event.ActionListener() {
					public void actionPerformed(java.awt.event.ActionEvent evt) {
						cp_saveCustChanges_buttonActionPerformed(evt);
					}
				});

		cp_custActivation_button.setText("Deactivate Customer");
		cp_custActivation_button
				.addActionListener(new java.awt.event.ActionListener() {
					public void actionPerformed(java.awt.event.ActionEvent evt) {
						cp_custActivation_buttonActionPerformed(evt);
					}
				});

		cp_selectCustomer_button.setText(". . .");
		cp_selectCustomer_button
				.addActionListener(new java.awt.event.ActionListener() {
					public void actionPerformed(java.awt.event.ActionEvent evt) {
						cp_selectCustomer_buttonActionPerformed(evt);
					}
				});

		cp_interval_field.setText("Interval");

		cp_print_button.setText("Print");
		cp_print_button.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				cp_print_buttonActionPerformed(evt);
			}
		});

		javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
		this.setLayout(layout);
		layout
				.setHorizontalGroup(layout
						.createParallelGroup(
								javax.swing.GroupLayout.Alignment.LEADING)
						.addGroup(
								layout
										.createSequentialGroup()
										.addGroup(
												layout
														.createParallelGroup(
																javax.swing.GroupLayout.Alignment.LEADING)
														.addGroup(
																layout
																		.createSequentialGroup()
																		.addContainerGap()
																		.addGroup(
																				layout
																						.createParallelGroup(
																								javax.swing.GroupLayout.Alignment.TRAILING)
																						.addComponent(
																								cp_custID_label)
																						.addComponent(
																								cp_directions_label)
																						.addComponent(
																								cp_priceSheet_label)
																						.addComponent(
																								cp_zipcode_label)
																						.addComponent(
																								cp_state_label)
																						.addComponent(
																								cp_city_label)
																						.addComponent(
																								cp_address_label)
																						.addComponent(
																								cp_name_label)
																						.addComponent(
																								cp_phoneNum_label1)
																						.addComponent(
																								cp_phoneNum_label2)
																						.addComponent(
																								cp_faxNum_label)
																						.addComponent(
																								cp_custStatus_label))
																		.addPreferredGap(
																				javax.swing.LayoutStyle.ComponentPlacement.RELATED)
																		.addGroup(
																				layout
																						.createParallelGroup(
																								javax.swing.GroupLayout.Alignment.LEADING)
																						.addComponent(
																								jScrollPane5,
																								javax.swing.GroupLayout.DEFAULT_SIZE,
																								208,
																								Short.MAX_VALUE)
																						.addComponent(
																								cp_custStatus_field)
																						.addComponent(
																								cp_faxNum_field,
																								javax.swing.GroupLayout.DEFAULT_SIZE,
																								208,
																								Short.MAX_VALUE)
																						.addComponent(
																								cp_phoneNum_field2,
																								javax.swing.GroupLayout.DEFAULT_SIZE,
																								208,
																								Short.MAX_VALUE)
																						.addGroup(
																								layout
																										.createSequentialGroup()
																										.addComponent(
																												cp_custID_field)
																										.addPreferredGap(
																												javax.swing.LayoutStyle.ComponentPlacement.RELATED,
																												125,
																												Short.MAX_VALUE)
																										.addComponent(
																												cp_selectCustomer_button))
																						.addComponent(
																								cp_phoneNum_field1,
																								javax.swing.GroupLayout.DEFAULT_SIZE,
																								208,
																								Short.MAX_VALUE)
																						.addComponent(
																								cp_priceSheet_combobox,
																								0,
																								208,
																								Short.MAX_VALUE)
																						.addComponent(
																								cp_city_field,
																								javax.swing.GroupLayout.DEFAULT_SIZE,
																								208,
																								Short.MAX_VALUE)
																						.addComponent(
																								cp_address_field2,
																								javax.swing.GroupLayout.DEFAULT_SIZE,
																								208,
																								Short.MAX_VALUE)
																						.addComponent(
																								cp_address_field1,
																								javax.swing.GroupLayout.DEFAULT_SIZE,
																								208,
																								Short.MAX_VALUE)
																						.addComponent(
																								cp_zipcode_field,
																								javax.swing.GroupLayout.DEFAULT_SIZE,
																								208,
																								Short.MAX_VALUE)
																						.addComponent(
																								cp_state_field,
																								javax.swing.GroupLayout.DEFAULT_SIZE,
																								208,
																								Short.MAX_VALUE)
																						.addComponent(
																								cp_name_field,
																								javax.swing.GroupLayout.PREFERRED_SIZE,
																								208,
																								javax.swing.GroupLayout.PREFERRED_SIZE))
																		.addGap(
																				53,
																				53,
																				53)
																		.addGroup(
																				layout
																						.createParallelGroup(
																								javax.swing.GroupLayout.Alignment.TRAILING)
																						.addGroup(
																								layout
																										.createParallelGroup(
																												javax.swing.GroupLayout.Alignment.LEADING,
																												false)
																										.addGroup(
																												javax.swing.GroupLayout.Alignment.TRAILING,
																												layout
																														.createSequentialGroup()
																														.addGap(
																																17,
																																17,
																																17)
																														.addComponent(
																																cp_taxExemptionCode_label))
																										.addGroup(
																												layout
																														.createParallelGroup(
																																javax.swing.GroupLayout.Alignment.TRAILING)
																														.addComponent(
																																cp_interval_label)
																														.addComponent(
																																cp_priceSheetTemplate_label)
																														.addComponent(
																																cp_foreman_label)
																														.addComponent(
																																cp_extSalespersonCode_label)
																														.addComponent(
																																cp_eachSheetCode_label)
																														.addComponent(
																																cp_marriett_label)))
																						.addComponent(
																								cp_salesmanCode_label)
																						.addComponent(
																								cp_printPriceSheet_label)
																						.addComponent(
																								cp_paymentTermsCode_label)
																						.addComponent(
																								cp_accountRep_label)
																						.addComponent(
																								cp_billToCustID_label)
																						.addComponent(
																								cp_financeChargeCode_label)
																						.addComponent(
																								cp_printStatements_label)
																						.addComponent(
																								cp_taxLiable_label)
																						.addComponent(
																								cp_taxAreaCode_label))
																		.addPreferredGap(
																				javax.swing.LayoutStyle.ComponentPlacement.RELATED)
																		.addGroup(
																				layout
																						.createParallelGroup(
																								javax.swing.GroupLayout.Alignment.LEADING,
																								false)
																						.addComponent(
																								cp_taxLiable_checkbox)
																						.addComponent(
																								cp_printStatements_checkbox)
																						.addComponent(
																								cp_interval_field,
																								javax.swing.GroupLayout.DEFAULT_SIZE,
																								101,
																								Short.MAX_VALUE)
																						.addComponent(
																								cp_foreman_combobox,
																								0,
																								javax.swing.GroupLayout.DEFAULT_SIZE,
																								Short.MAX_VALUE)
																						.addComponent(
																								cp_extSalespersonCode_combobox,
																								0,
																								javax.swing.GroupLayout.DEFAULT_SIZE,
																								Short.MAX_VALUE)
																						.addComponent(
																								cp_salesmanCode_combobox,
																								0,
																								javax.swing.GroupLayout.DEFAULT_SIZE,
																								Short.MAX_VALUE)
																						.addComponent(
																								cp_priceSheetTemplate_combobox,
																								0,
																								javax.swing.GroupLayout.DEFAULT_SIZE,
																								Short.MAX_VALUE)
																						.addComponent(
																								cp_printPriceSheet_field,
																								javax.swing.GroupLayout.DEFAULT_SIZE,
																								javax.swing.GroupLayout.DEFAULT_SIZE,
																								Short.MAX_VALUE)
																						.addComponent(
																								cp_paymentTermsCode_combobox,
																								0,
																								javax.swing.GroupLayout.DEFAULT_SIZE,
																								Short.MAX_VALUE)
																						.addComponent(
																								cp_eachSheetCode_combobox,
																								0,
																								javax.swing.GroupLayout.DEFAULT_SIZE,
																								Short.MAX_VALUE)
																						.addComponent(
																								cp_marriett_field,
																								javax.swing.GroupLayout.DEFAULT_SIZE,
																								javax.swing.GroupLayout.DEFAULT_SIZE,
																								Short.MAX_VALUE)
																						.addComponent(
																								cp_accountRep_field)
																						.addComponent(
																								cp_billToCustID_combobox,
																								0,
																								javax.swing.GroupLayout.DEFAULT_SIZE,
																								Short.MAX_VALUE)
																						.addComponent(
																								cp_financeChargeCode_combobox,
																								0,
																								javax.swing.GroupLayout.DEFAULT_SIZE,
																								Short.MAX_VALUE)
																						.addComponent(
																								cp_taxExemptionCode_combobox,
																								0,
																								javax.swing.GroupLayout.DEFAULT_SIZE,
																								Short.MAX_VALUE)
																						.addComponent(
																								cp_taxAreaCode_combobox,
																								0,
																								javax.swing.GroupLayout.DEFAULT_SIZE,
																								Short.MAX_VALUE)))
														.addGroup(
																layout
																		.createSequentialGroup()
																		.addGap(
																				109,
																				109,
																				109)
																		.addComponent(
																				cp_saveCustChanges_button)
																		.addGap(
																				85,
																				85,
																				85)
																		.addComponent(
																				cp_print_button)
																		.addGap(
																				82,
																				82,
																				82)
																		.addComponent(
																				cp_custActivation_button)))
										.addContainerGap(403, Short.MAX_VALUE)));
		layout
				.setVerticalGroup(layout
						.createParallelGroup(
								javax.swing.GroupLayout.Alignment.LEADING)
						.addGroup(
								layout
										.createSequentialGroup()
										.addContainerGap()
										.addGroup(
												layout
														.createParallelGroup(
																javax.swing.GroupLayout.Alignment.LEADING)
														.addGroup(
																layout
																		.createSequentialGroup()
																		.addGroup(
																				layout
																						.createParallelGroup(
																								javax.swing.GroupLayout.Alignment.BASELINE)
																						.addComponent(
																								cp_custID_label)
																						.addComponent(
																								cp_custID_field)
																						.addComponent(
																								cp_selectCustomer_button))
																		.addGap(
																				8,
																				8,
																				8)
																		.addGroup(
																				layout
																						.createParallelGroup(
																								javax.swing.GroupLayout.Alignment.BASELINE)
																						.addComponent(
																								cp_custStatus_label)
																						.addComponent(
																								cp_custStatus_field))
																		.addPreferredGap(
																				javax.swing.LayoutStyle.ComponentPlacement.RELATED)
																		.addGroup(
																				layout
																						.createParallelGroup(
																								javax.swing.GroupLayout.Alignment.BASELINE)
																						.addComponent(
																								cp_name_label)
																						.addComponent(
																								cp_name_field,
																								javax.swing.GroupLayout.PREFERRED_SIZE,
																								javax.swing.GroupLayout.DEFAULT_SIZE,
																								javax.swing.GroupLayout.PREFERRED_SIZE))
																		.addPreferredGap(
																				javax.swing.LayoutStyle.ComponentPlacement.RELATED)
																		.addGroup(
																				layout
																						.createParallelGroup(
																								javax.swing.GroupLayout.Alignment.BASELINE)
																						.addComponent(
																								cp_address_label)
																						.addComponent(
																								cp_address_field1,
																								javax.swing.GroupLayout.PREFERRED_SIZE,
																								javax.swing.GroupLayout.DEFAULT_SIZE,
																								javax.swing.GroupLayout.PREFERRED_SIZE))
																		.addPreferredGap(
																				javax.swing.LayoutStyle.ComponentPlacement.RELATED)
																		.addComponent(
																				cp_address_field2,
																				javax.swing.GroupLayout.PREFERRED_SIZE,
																				javax.swing.GroupLayout.DEFAULT_SIZE,
																				javax.swing.GroupLayout.PREFERRED_SIZE)
																		.addPreferredGap(
																				javax.swing.LayoutStyle.ComponentPlacement.RELATED)
																		.addGroup(
																				layout
																						.createParallelGroup(
																								javax.swing.GroupLayout.Alignment.BASELINE)
																						.addComponent(
																								cp_city_label)
																						.addComponent(
																								cp_city_field,
																								javax.swing.GroupLayout.PREFERRED_SIZE,
																								javax.swing.GroupLayout.DEFAULT_SIZE,
																								javax.swing.GroupLayout.PREFERRED_SIZE))
																		.addPreferredGap(
																				javax.swing.LayoutStyle.ComponentPlacement.RELATED)
																		.addGroup(
																				layout
																						.createParallelGroup(
																								javax.swing.GroupLayout.Alignment.BASELINE)
																						.addComponent(
																								cp_state_label)
																						.addComponent(
																								cp_state_field,
																								javax.swing.GroupLayout.PREFERRED_SIZE,
																								javax.swing.GroupLayout.DEFAULT_SIZE,
																								javax.swing.GroupLayout.PREFERRED_SIZE))
																		.addPreferredGap(
																				javax.swing.LayoutStyle.ComponentPlacement.RELATED)
																		.addGroup(
																				layout
																						.createParallelGroup(
																								javax.swing.GroupLayout.Alignment.BASELINE)
																						.addComponent(
																								cp_zipcode_label)
																						.addComponent(
																								cp_zipcode_field,
																								javax.swing.GroupLayout.PREFERRED_SIZE,
																								javax.swing.GroupLayout.DEFAULT_SIZE,
																								javax.swing.GroupLayout.PREFERRED_SIZE))
																		.addPreferredGap(
																				javax.swing.LayoutStyle.ComponentPlacement.RELATED)
																		.addGroup(
																				layout
																						.createParallelGroup(
																								javax.swing.GroupLayout.Alignment.BASELINE)
																						.addComponent(
																								cp_priceSheet_label)
																						.addComponent(
																								cp_priceSheet_combobox,
																								javax.swing.GroupLayout.PREFERRED_SIZE,
																								javax.swing.GroupLayout.DEFAULT_SIZE,
																								javax.swing.GroupLayout.PREFERRED_SIZE))
																		.addPreferredGap(
																				javax.swing.LayoutStyle.ComponentPlacement.RELATED)
																		.addGroup(
																				layout
																						.createParallelGroup(
																								javax.swing.GroupLayout.Alignment.LEADING)
																						.addComponent(
																								cp_directions_label)
																						.addComponent(
																								jScrollPane5,
																								javax.swing.GroupLayout.PREFERRED_SIZE,
																								javax.swing.GroupLayout.DEFAULT_SIZE,
																								javax.swing.GroupLayout.PREFERRED_SIZE))
																		.addPreferredGap(
																				javax.swing.LayoutStyle.ComponentPlacement.RELATED)
																		.addGroup(
																				layout
																						.createParallelGroup(
																								javax.swing.GroupLayout.Alignment.BASELINE)
																						.addComponent(
																								cp_phoneNum_label1)
																						.addComponent(
																								cp_phoneNum_field1,
																								javax.swing.GroupLayout.PREFERRED_SIZE,
																								javax.swing.GroupLayout.DEFAULT_SIZE,
																								javax.swing.GroupLayout.PREFERRED_SIZE))
																		.addPreferredGap(
																				javax.swing.LayoutStyle.ComponentPlacement.RELATED)
																		.addGroup(
																				layout
																						.createParallelGroup(
																								javax.swing.GroupLayout.Alignment.BASELINE)
																						.addComponent(
																								cp_phoneNum_field2,
																								javax.swing.GroupLayout.PREFERRED_SIZE,
																								javax.swing.GroupLayout.DEFAULT_SIZE,
																								javax.swing.GroupLayout.PREFERRED_SIZE)
																						.addComponent(
																								cp_phoneNum_label2))
																		.addPreferredGap(
																				javax.swing.LayoutStyle.ComponentPlacement.RELATED)
																		.addGroup(
																				layout
																						.createParallelGroup(
																								javax.swing.GroupLayout.Alignment.BASELINE)
																						.addComponent(
																								cp_faxNum_label)
																						.addComponent(
																								cp_faxNum_field,
																								javax.swing.GroupLayout.PREFERRED_SIZE,
																								javax.swing.GroupLayout.DEFAULT_SIZE,
																								javax.swing.GroupLayout.PREFERRED_SIZE)))
														.addGroup(
																layout
																		.createSequentialGroup()
																		.addGroup(
																				layout
																						.createParallelGroup(
																								javax.swing.GroupLayout.Alignment.BASELINE)
																						.addComponent(
																								cp_foreman_label)
																						.addComponent(
																								cp_foreman_combobox,
																								javax.swing.GroupLayout.PREFERRED_SIZE,
																								javax.swing.GroupLayout.DEFAULT_SIZE,
																								javax.swing.GroupLayout.PREFERRED_SIZE))
																		.addPreferredGap(
																				javax.swing.LayoutStyle.ComponentPlacement.RELATED)
																		.addGroup(
																				layout
																						.createParallelGroup(
																								javax.swing.GroupLayout.Alignment.BASELINE)
																						.addComponent(
																								cp_extSalespersonCode_label)
																						.addComponent(
																								cp_extSalespersonCode_combobox,
																								javax.swing.GroupLayout.PREFERRED_SIZE,
																								javax.swing.GroupLayout.DEFAULT_SIZE,
																								javax.swing.GroupLayout.PREFERRED_SIZE))
																		.addPreferredGap(
																				javax.swing.LayoutStyle.ComponentPlacement.RELATED)
																		.addGroup(
																				layout
																						.createParallelGroup(
																								javax.swing.GroupLayout.Alignment.BASELINE)
																						.addComponent(
																								cp_salesmanCode_label)
																						.addComponent(
																								cp_salesmanCode_combobox,
																								javax.swing.GroupLayout.PREFERRED_SIZE,
																								javax.swing.GroupLayout.DEFAULT_SIZE,
																								javax.swing.GroupLayout.PREFERRED_SIZE))
																		.addPreferredGap(
																				javax.swing.LayoutStyle.ComponentPlacement.RELATED)
																		.addGroup(
																				layout
																						.createParallelGroup(
																								javax.swing.GroupLayout.Alignment.BASELINE)
																						.addComponent(
																								cp_interval_label)
																						.addComponent(
																								cp_interval_field,
																								javax.swing.GroupLayout.PREFERRED_SIZE,
																								javax.swing.GroupLayout.DEFAULT_SIZE,
																								javax.swing.GroupLayout.PREFERRED_SIZE))
																		.addPreferredGap(
																				javax.swing.LayoutStyle.ComponentPlacement.RELATED)
																		.addGroup(
																				layout
																						.createParallelGroup(
																								javax.swing.GroupLayout.Alignment.BASELINE)
																						.addComponent(
																								cp_priceSheetTemplate_label)
																						.addComponent(
																								cp_priceSheetTemplate_combobox,
																								javax.swing.GroupLayout.PREFERRED_SIZE,
																								javax.swing.GroupLayout.DEFAULT_SIZE,
																								javax.swing.GroupLayout.PREFERRED_SIZE))
																		.addPreferredGap(
																				javax.swing.LayoutStyle.ComponentPlacement.RELATED)
																		.addGroup(
																				layout
																						.createParallelGroup(
																								javax.swing.GroupLayout.Alignment.BASELINE)
																						.addComponent(
																								cp_printPriceSheet_label)
																						.addComponent(
																								cp_printPriceSheet_field))
																		.addPreferredGap(
																				javax.swing.LayoutStyle.ComponentPlacement.RELATED)
																		.addGroup(
																				layout
																						.createParallelGroup(
																								javax.swing.GroupLayout.Alignment.BASELINE)
																						.addComponent(
																								cp_paymentTermsCode_label)
																						.addComponent(
																								cp_paymentTermsCode_combobox,
																								javax.swing.GroupLayout.PREFERRED_SIZE,
																								javax.swing.GroupLayout.DEFAULT_SIZE,
																								javax.swing.GroupLayout.PREFERRED_SIZE))
																		.addPreferredGap(
																				javax.swing.LayoutStyle.ComponentPlacement.RELATED)
																		.addGroup(
																				layout
																						.createParallelGroup(
																								javax.swing.GroupLayout.Alignment.LEADING)
																						.addComponent(
																								cp_eachSheetCode_label)
																						.addComponent(
																								cp_eachSheetCode_combobox,
																								javax.swing.GroupLayout.PREFERRED_SIZE,
																								javax.swing.GroupLayout.DEFAULT_SIZE,
																								javax.swing.GroupLayout.PREFERRED_SIZE))
																		.addPreferredGap(
																				javax.swing.LayoutStyle.ComponentPlacement.RELATED)
																		.addGroup(
																				layout
																						.createParallelGroup(
																								javax.swing.GroupLayout.Alignment.BASELINE)
																						.addComponent(
																								cp_marriett_label)
																						.addComponent(
																								cp_marriett_field))
																		.addPreferredGap(
																				javax.swing.LayoutStyle.ComponentPlacement.RELATED)
																		.addGroup(
																				layout
																						.createParallelGroup(
																								javax.swing.GroupLayout.Alignment.BASELINE)
																						.addComponent(
																								cp_accountRep_label)
																						.addComponent(
																								cp_accountRep_field,
																								javax.swing.GroupLayout.PREFERRED_SIZE,
																								javax.swing.GroupLayout.DEFAULT_SIZE,
																								javax.swing.GroupLayout.PREFERRED_SIZE))
																		.addPreferredGap(
																				javax.swing.LayoutStyle.ComponentPlacement.RELATED)
																		.addGroup(
																				layout
																						.createParallelGroup(
																								javax.swing.GroupLayout.Alignment.BASELINE)
																						.addComponent(
																								cp_billToCustID_label)
																						.addComponent(
																								cp_billToCustID_combobox,
																								javax.swing.GroupLayout.PREFERRED_SIZE,
																								javax.swing.GroupLayout.DEFAULT_SIZE,
																								javax.swing.GroupLayout.PREFERRED_SIZE))
																		.addPreferredGap(
																				javax.swing.LayoutStyle.ComponentPlacement.RELATED)
																		.addGroup(
																				layout
																						.createParallelGroup(
																								javax.swing.GroupLayout.Alignment.BASELINE)
																						.addComponent(
																								cp_financeChargeCode_label)
																						.addComponent(
																								cp_financeChargeCode_combobox,
																								javax.swing.GroupLayout.PREFERRED_SIZE,
																								javax.swing.GroupLayout.DEFAULT_SIZE,
																								javax.swing.GroupLayout.PREFERRED_SIZE))
																		.addPreferredGap(
																				javax.swing.LayoutStyle.ComponentPlacement.RELATED)
																		.addGroup(
																				layout
																						.createParallelGroup(
																								javax.swing.GroupLayout.Alignment.LEADING)
																						.addComponent(
																								cp_printStatements_checkbox)
																						.addComponent(
																								cp_printStatements_label))
																		.addGap(
																				8,
																				8,
																				8)
																		.addGroup(
																				layout
																						.createParallelGroup(
																								javax.swing.GroupLayout.Alignment.TRAILING)
																						.addComponent(
																								cp_taxLiable_checkbox)
																						.addComponent(
																								cp_taxLiable_label))
																		.addPreferredGap(
																				javax.swing.LayoutStyle.ComponentPlacement.RELATED)
																		.addGroup(
																				layout
																						.createParallelGroup(
																								javax.swing.GroupLayout.Alignment.BASELINE)
																						.addComponent(
																								cp_taxExemptionCode_label)
																						.addComponent(
																								cp_taxExemptionCode_combobox,
																								javax.swing.GroupLayout.PREFERRED_SIZE,
																								javax.swing.GroupLayout.DEFAULT_SIZE,
																								javax.swing.GroupLayout.PREFERRED_SIZE))
																		.addPreferredGap(
																				javax.swing.LayoutStyle.ComponentPlacement.RELATED)
																		.addGroup(
																				layout
																						.createParallelGroup(
																								javax.swing.GroupLayout.Alignment.BASELINE)
																						.addComponent(
																								cp_taxAreaCode_label)
																						.addComponent(
																								cp_taxAreaCode_combobox,
																								javax.swing.GroupLayout.PREFERRED_SIZE,
																								javax.swing.GroupLayout.DEFAULT_SIZE,
																								javax.swing.GroupLayout.PREFERRED_SIZE))))
										.addGap(80, 80, 80)
										.addGroup(
												layout
														.createParallelGroup(
																javax.swing.GroupLayout.Alignment.BASELINE)
														.addComponent(
																cp_saveCustChanges_button)
														.addComponent(
																cp_custActivation_button)
														.addComponent(
																cp_print_button))
										.addContainerGap(117, Short.MAX_VALUE)));
	}// </editor-fold>
	//GEN-END:initComponents

	private void cp_print_buttonActionPerformed(java.awt.event.ActionEvent evt) {
		// TODO add your handling code here:
		this.print();
	}

	private void ccs_ok_buttonActionPerformed(java.awt.event.ActionEvent evt) {
		custChangesSaved_dialog.setVisible(false);
	}

	//TODO: Start of our code

	private void selectCust_dialog_CUSTOMER_buttonActionPerformed(
			java.awt.event.ActionEvent evt) {
		int CustID = MEDIATOR
				.getCustomerEditID((String) selectCust_dialog_CUSTOMER_combobox
						.getSelectedItem());
		if (CustID == -1) {
			selectCust_dialog_CUSTOMER_error
					.setText("Please select a valid customer");
		} else {
			cp_custID_field.setText(Integer.toString(CustID));
			selectCust_dialog_CUSTOMER.setVisible(false);
			updateSelectForemanComboboxInCUSTOMER();
			updateSelectExtSalespersonCodeComboboxInCUSTOMER();
			updateSelectSalespersonCodeComboboxInCUSTOMER();
			updateSelectBillToCustomerIDComboboxInCUSTOMER();
			updatePriceSheetCombobox();
			updatePriceSheetTemplateCombobox();
			fill_Customer_Screen();
		}
	}

	private void OKActionPerformed(java.awt.event.ActionEvent evt) {
		this.fieldsFail.hide();
	}

	private void cp_selectCustomer_buttonActionPerformed(
			java.awt.event.ActionEvent evt) {
		//TODO: fix this code
		selectCust_dialog_CUSTOMER.setVisible(true);
		updateSelectCustomerComboboxInCUSTOMER();
	}

	private void cp_custActivation_buttonActionPerformed(
			java.awt.event.ActionEvent evt) {
		if (cp_custActivation_button.getText().equals(ACTIVATE_CUSTOMER)) {
			if (cp_custID_field.getText().equals(EMPTY_CUSTOMER_ID)) {
				this.message.setText("No Customer to Deactivate");
				this.message2.setText("");
				this.fieldsFail.setVisible(true);
				this.fieldsFail.toFront();
			} else {
				cp_custActivation_button.setText(DEACTIVATE_CUSTOMER);
				cp_custStatus_field.setText(ACTIVE);
			}

		} else {
			// Checks if there is actually a customer to deactivate.
			if (cp_custID_field.getText().equals(EMPTY_CUSTOMER_ID)) {
				this.message2.setText("");
				this.message.setText("No Customer to Deactivate");
				this.fieldsFail.setVisible(true);
				this.fieldsFail.toFront();
				// Checks if the customer has customers sinding their billing id's to them.
			} else if (MEDIATOR.checkCustomerDependencies(Integer
					.parseInt(cp_custID_field.getText()))) {
				ArrayList<String> failcode = MEDIATOR
						.getCustomerDependencies(Integer
								.parseInt(cp_custID_field.getText()));
				if (failcode.size() > 0) {
					String error_str = "Customer can't be deactivated. These customers rout their billing to this customer:";
					String error_str2 = "<html><p style=\"text-align: center; color: red;\">";
					for (int i = 0; i < failcode.size(); i++) {
						error_str2 += failcode.get(i);
						if (i != failcode.size() - 1) {
							error_str2 += "<p style=\"text-align: center; color: red;\">";
						} else {
							error_str2 += "</p></html>";
						}
						System.out.println(failcode.get(i));
					}
					// Display the error box.
					System.out.println(error_str2);
					this.message.setText(error_str);
					this.message2.setText(error_str2);
					this.fieldsFail.setVisible(true);
					this.fieldsFail.toFront();
				}
			} else {

				cp_custActivation_button.setText(ACTIVATE_CUSTOMER);
				cp_custStatus_field.setText(INACTIVE);
			}
		}
	}

	@SuppressWarnings("deprecation")
	private void cp_saveCustChanges_buttonActionPerformed(
			java.awt.event.ActionEvent evt) {
		cp_state_field.setText(cp_state_field.getText().toUpperCase());

		ArrayList<String> failcode = new ArrayList<String>();

		// Error checking the name field.
		if (cp_name_field.getText().length() == 0
				|| cp_name_field.getText().substring(0).equals(" ")
				|| Character.toString(cp_name_field.getText().charAt(0))
						.equals(" ")) {
			failcode.add(cp_name_label.getText());
		} else if (MEDIATOR.doesCustNameExist(cp_name_field.getText())
				&& cp_custID_field.equals(EMPTY_CUSTOMER_ID)) {
			failcode.add("Customer name already exists");
		}

		// Error checking the address1 field.
		if (cp_address_field1.getText().length() == 0
				|| checkIfDouble(cp_address_field1.getText())
				|| Character.toString(cp_address_field1.getText().charAt(0))
						.equals(" ")) {
			failcode.add(cp_address_label.getText());
		}

		// Error checking the address2 field.
		if (cp_address_field2.getText().length() != 0
				&& checkIfDouble(cp_address_field2.getText())) {
			failcode.add(cp_address_label.getText());
		}

		// Error checking the city field.
		if (cp_city_field.getText().length() == 0
				|| checkIfDouble(cp_city_field.getText())
				|| Character.toString(cp_city_field.getText().charAt(0))
						.equals(" ")) {
			failcode.add(cp_city_label.getText());
		}

		// Error checking the state field.
		if (cp_state_field.getText().length() != 2
				|| checkStates(cp_state_field.getText()) == false
				|| Character.toString(cp_state_field.getText().charAt(0))
						.equals(" ")) {
			failcode.add(cp_state_label.getText());
		}

		// Error checking the zip field.
		if ((cp_zipcode_field.getText().length() != ZIP_LENGTH_MIN && cp_zipcode_field
				.getText().length() != ZIP_LENGTH_MAX)
				|| !checkIfDouble(cp_zipcode_field.getText())
				|| Character.toString(cp_zipcode_field.getText().charAt(0))
						.equals(" ")) {
			failcode.add(cp_zipcode_label.getText());
		}

		// Error checking the phone1 field.
		if ((cp_phoneNum_field1.getText().length() < PHONE_LENGTH_MIN || cp_phoneNum_field1
				.getText().length() > PHONE_LENGTH_MAX)
				|| !checkIfDouble(cp_phoneNum_field1.getText())
				|| Character.toString(cp_phoneNum_field1.getText().charAt(0))
						.equals(" ")) {
			failcode.add(cp_phoneNum_label1.getText());
		}

		// Error checking the phone2 field.
		if (cp_phoneNum_field2.getText().length() != 0
				&& (!checkIfDouble(cp_phoneNum_field2.getText()) || (cp_phoneNum_field2
						.getText().length() < PHONE_LENGTH_MIN || cp_phoneNum_field2
						.getText().length() > PHONE_LENGTH_MAX))) {
			failcode.add(cp_phoneNum_label2.getText());
		}

		// Error checking the fax field.
		if (cp_faxNum_field.getText().length() != 0
				&& (!checkIfDouble(cp_faxNum_field.getText()) || (cp_faxNum_field
						.getText().length() < PHONE_LENGTH_MIN || cp_faxNum_field
						.getText().length() > PHONE_LENGTH_MAX))) {
			failcode.add(cp_faxNum_label.getText());
		}

		// Error checking the foreman box.
		if (cp_foreman_combobox.getSelectedItem().toString().equals(
				SELECT_FOREMAN)) {
			failcode.add(cp_foreman_label.getText());
		}

		// Error checking the External Salesperson Box
		if (cp_extSalespersonCode_combobox.getSelectedItem().toString().equals(
				SELECT_EXTERNAL_SALESPERSON)) {
			failcode.add(cp_extSalespersonCode_label.getText());
		}

		// Error checking the Salesman Box.
		if (cp_salesmanCode_combobox.getSelectedItem().toString().equals(
				SELECT_SALESPERSON)) {
			failcode.add(cp_salesmanCode_label.getText());
		}

		// Error Checking the Price Sheet Contact Box
		if (cp_priceSheet_combobox.getSelectedItem().toString().equals(
				SELECT_PRICE_SHEET)) {
			failcode.add(cp_priceSheet_label.getText());
		}

		// Error Checking the Price Group Code Box
		if (cp_priceSheetTemplate_combobox.getSelectedItem().toString().equals(
				SELECT_PRICE_GROUP)) {
			failcode.add(cp_priceSheetTemplate_label.getText());
		}

		// Error checking the Bill To Cust ID Box
		if ((cp_billToCustID_combobox.getSelectedItem().toString()
				.equals(SELECT_CUSTID))) {
			failcode.add(cp_billToCustID_label.getText());
		}

		System.out.println(cp_interval_field.getText().length());
		// Error checking the Prior Sales Interval box
		if ((cp_interval_field.getText().length() < INTERVAL_LENGTH_MIN || cp_interval_field
				.getText().length() > INTERVAL_LENGTH_MAX)
				|| !checkIfInt(cp_interval_field.getText())
				|| Character.toString(cp_interval_field.getText().charAt(0))
						.equals(" ")
				|| Integer.parseInt(cp_interval_field.getText().toString()) < 0) {
			failcode.add(cp_interval_label.getText());
		}

		// If there are any errors in the failcode array, report the errors to the user.
		if (failcode.size() > 0) {
			String error_str = "Please fill out the following fields to complete the form:";
			String error_str2 = "<html><p style=\"text-align: center; color: red;\">";
			for (int i = 0; i < failcode.size(); i++) {
				error_str2 += failcode.get(i);
				if (i != failcode.size() - 1) {
					error_str2 += "<p style=\"text-align: center; color: red;\">";
				} else {
					error_str2 += "</p></html>";
				}
				System.out.println(failcode.get(i));
			}
			// Display the error box.
			System.out.println(error_str2);
			this.message.setText(error_str);
			this.message2.setText(error_str2);
			this.fieldsFail.setVisible(true);
			this.fieldsFail.toFront();
		}

		// Else create a customer object to be passed into the DAO.
		else {
			cp_state_field.setText(cp_state_field.getText().toUpperCase());

			Customers cust1 = getCustomerInfo();
			CustomersPk custPk = getCustomerPk();

			// If the customer already exists, edit the customer.
			if (!cp_custID_field.getText().equals(EMPTY_CUSTOMER_ID)) {
				cust1
						.setCustomerID(Integer.parseInt(cp_custID_field
								.getText()));
				custPk.setCustomerID(Integer
						.parseInt(cp_custID_field.getText()));
				MEDIATOR.updateCustomers(custPk, cust1);
				ccs_label.setText("Customer changes have been saved!");
				custChangesSaved_dialog.setVisible(true);
			}
			// Else create a new customer in the database with a unique id.
			else {
				int id = MEDIATOR.customerAutoIncrement();
				cust1.setCustomerID(id);
				MEDIATOR.insertCustomer(cust1);
				cp_custID_field.setText("" + id);
				ccs_label.setText("Customer has been created!");
				custChangesSaved_dialog.setVisible(true);

				// TODO: Bill-to cust id stuff
			}
		}
	}

	private boolean checkIfDouble(String text) {
		// Checking if the text contains any letters.
		try {
			Double.parseDouble(text);
		} catch (NumberFormatException nfe) {
			return false;
		}
		return true;
	}

	private boolean checkIfInt(String text) {
		// Checking if the text contains any letters.
		try {
			Integer.parseInt(text);
		} catch (NumberFormatException nfe) {
			return false;
		}
		return true;
	}

	private boolean checkStates(String state) {
		String[] states = { "AL", "AK", "AZ", "AR", "CA", "CO", "CT", "DE",
				"FL", "GA", "HI", "ID", "IL", "IN", "IA", "KS", "KY", "LA",
				"ME", "MD", "MA", "MI", "MN", "MS", "MO", "MT", "NE", "NV",
				"NH", "NJ", "NM", "NY", "NC", "ND", "OH", "OK", "OR", "PA",
				"RI", "SC", "SD", "TN", "TX", "UT", "VT", "VA", "WA", "WV",
				"WI", "WY" };
		System.out.println(state);
		System.out.println(states[41]);
		for (int i = 0; i < states.length; i++) {
			if (state.equals(states[i])) {
				return true;
			}
		}
		return false;
	}

	// Gets all customer info displayed on the screen and returns it in a Customers object.
	private Customers getCustomerInfo() {
		Customers cust1 = new Customers();

		cust1.setCustomerName(cp_name_field.getText());
		cust1.setAddressLine1(cp_address_field1.getText());
		cust1.setAddressLine2(cp_address_field2.getText());
		cust1.setCity(cp_city_field.getText());
		cust1.setState(cp_state_field.getText());
		cust1.setZipCode(cp_zipcode_field.getText());
		cust1.setDirections(cp_directions_field.getText());
		cust1.setPhoneNum1(cp_phoneNum_field1.getText());
		cust1.setPhoneNum2(cp_phoneNum_field2.getText());
		cust1.setFaxNum(cp_faxNum_field.getText());
		cust1.setBillingID(Integer.parseInt(cp_custID_field.getText()));
		if ((cp_custStatus_field.getText()).equals(ACTIVE)) {
			System.out.println("Customer status set to 1.");
			cust1.setIsActive((short) 1);
		} else if (cp_custStatus_field.getText().equals(INACTIVE)) {
			System.out.println("Customer status set to 0;");
			cust1.setIsActive((short) 0);
		} else {
			System.out.println("Customer status was not set.");
		}
		cust1.setHistoryInterval(Integer.parseInt(cp_interval_field.getText()));
		System.out.println(Integer.parseInt(cp_interval_field.getText()));
		ArrayList<Employee> newExtSalespersonList = MEDIATOR
				.getExternalSalespersonList();
		for (int i = 0; i < newExtSalespersonList.size(); i++) {
			if (cp_extSalespersonCode_combobox.getSelectedItem().toString()
					.equals(newExtSalespersonList.get(i).getLastName())) {
				cust1.setExternalSalespersonID(newExtSalespersonList.get(i)
						.getEmployeeID());
			}
		}

		ArrayList<Employee> newSalespersonList = MEDIATOR.getSalespersonList();
		for (int i = 0; i < newSalespersonList.size(); i++) {
			if (cp_salesmanCode_combobox.getSelectedItem().toString().equals(
					newSalespersonList.get(i).getLastName())) {
				cust1.setSalespersonID(newSalespersonList.get(i)
						.getEmployeeID());
			}
		}

		ArrayList<Employee> newForemanList = MEDIATOR.getForemanList();
		for (int i = 0; i < newForemanList.size(); i++) {
			if (cp_foreman_combobox.getSelectedItem().toString().equals(
					newForemanList.get(i).getLastName())) {
				cust1.setForemanID(newForemanList.get(i).getEmployeeID());
			}
		}

		// Gets the Billing ID
		if (cp_billToCustID_combobox.getSelectedItem().toString() == DEFAULT_BILL_TO_ID) {
			cust1.setBillingID(MEDIATOR.customerAutoIncrement());
		} else {
			cust1.setBillingID(Integer.parseInt(cp_billToCustID_combobox
					.getSelectedItem().toString()));
		}

		// Gets the Price Sheet Contact 
		ArrayList<Pricesheets> newPriceSheetContactList = MEDIATOR
				.getEditPriceSheets();
		for (int i = 0; i < newPriceSheetContactList.size(); i++) {
			if (cp_priceSheet_combobox.getSelectedItem().toString().equals(
					newPriceSheetContactList.get(i).getPriceSheetName())) {
				cust1.setPriceSheet(newPriceSheetContactList.get(i)
						.getPriceSheetID());
			}
		}

		// Gets the Price Group Code 
		ArrayList<Pricesheets> newPriceGroupCodeList = MEDIATOR
				.getPriceSheetTemplates();
		for (int i = 0; i < newPriceGroupCodeList.size(); i++) {
			if (cp_priceSheetTemplate_combobox.getSelectedItem().toString()
					.equals(newPriceGroupCodeList.get(i).getPriceSheetName())) {
				cust1.setPriceSheetTemplate(newPriceGroupCodeList.get(i)
						.getPriceSheetID());
			}
		}

		return cust1;

	}

	private CustomersPk getCustomerPk() {
		CustomersPk custPk = new CustomersPk();
		int CustID = Integer.parseInt(cp_custID_field.getText());
		custPk.setCustomerID(CustID);
		return custPk;
	}

	private void cp_accountRep_fieldFocusGained(java.awt.event.FocusEvent evt) {
		if (cp_accountRep_field.getText().equals("Rep Name")) {
			this.cp_accountRep_field.setText("");
		}
	}

	private void cp_faxNum_fieldFocusGained(java.awt.event.FocusEvent evt) {
		if (cp_faxNum_field.getText().equals("Fax Number")) {
			this.cp_faxNum_field.setText("");
		}
	}

	private void cp_phoneNum_field2FocusGained(java.awt.event.FocusEvent evt) {
		if (cp_phoneNum_field2.getText().equals("Phone Number 2")) {
			this.cp_phoneNum_field2.setText("");
		}
	}

	private void cp_phoneNum_field1FocusGained(java.awt.event.FocusEvent evt) {
		if (cp_phoneNum_field1.getText().equals("Phone Number 1")) {
			this.cp_phoneNum_field1.setText("");
		}
	}

	private void cp_zipcode_fieldFocusGained(java.awt.event.FocusEvent evt) {
		if (cp_zipcode_field.getText().equals("Zip")) {
			this.cp_zipcode_field.setText("");
		}
	}

	private void cp_state_fieldFocusGained(java.awt.event.FocusEvent evt) {
		if (cp_state_field.getText().equals("State")) {
			this.cp_state_field.setText("");
		}
	}

	private void cp_city_fieldFocusGained(java.awt.event.FocusEvent evt) {
		if (cp_city_field.getText().equals("City")) {
			this.cp_city_field.setText("");
		}
	}

	private void cp_address_field2FocusGained(java.awt.event.FocusEvent evt) {
		if (cp_address_field2.getText().equals("Address Line 2")) {
			this.cp_address_field2.setText("");
		}
	}

	private void cp_address_field1FocusGained(java.awt.event.FocusEvent evt) {
		if (cp_address_field1.getText().equals("Address Line 1")) {
			this.cp_address_field1.setText("");
		}
	}

	private void cp_name_fieldFocusGained(java.awt.event.FocusEvent evt) {
		if (cp_name_field.getText().equals("Name")) {
			this.cp_name_field.setText("");
		}
	}

	private void cp_name_fieldActionPerformed(java.awt.event.ActionEvent evt) {
		this.cp_name_field.setText("");
	}

	//GEN-BEGIN:variables
	// Variables declaration - do not modify
	private javax.swing.JButton OK;
	private javax.swing.JLabel ccs_label;
	private javax.swing.JButton ccs_ok_button;
	private javax.swing.JTextField cp_accountRep_field;
	private javax.swing.JLabel cp_accountRep_label;
	private javax.swing.JTextField cp_address_field1;
	private javax.swing.JTextField cp_address_field2;
	private javax.swing.JLabel cp_address_label;
	private javax.swing.JComboBox cp_billToCustID_combobox;
	private javax.swing.JLabel cp_billToCustID_label;
	private javax.swing.JTextField cp_city_field;
	private javax.swing.JLabel cp_city_label;
	private javax.swing.JButton cp_custActivation_button;
	private javax.swing.JLabel cp_custID_field;
	private javax.swing.JLabel cp_custID_label;
	private javax.swing.JLabel cp_custStatus_field;
	private javax.swing.JLabel cp_custStatus_label;
	private javax.swing.JTextArea cp_directions_field;
	private javax.swing.JLabel cp_directions_label;
	private javax.swing.JComboBox cp_eachSheetCode_combobox;
	private javax.swing.JLabel cp_eachSheetCode_label;
	private javax.swing.JComboBox cp_extSalespersonCode_combobox;
	private javax.swing.JLabel cp_extSalespersonCode_label;
	private javax.swing.JTextField cp_faxNum_field;
	private javax.swing.JLabel cp_faxNum_label;
	private javax.swing.JComboBox cp_financeChargeCode_combobox;
	private javax.swing.JLabel cp_financeChargeCode_label;
	private javax.swing.JComboBox cp_foreman_combobox;
	private javax.swing.JLabel cp_foreman_label;
	private javax.swing.JTextField cp_interval_field;
	private javax.swing.JLabel cp_interval_label;
	private javax.swing.JLabel cp_marriett_field;
	private javax.swing.JLabel cp_marriett_label;
	private javax.swing.JTextField cp_name_field;
	private javax.swing.JLabel cp_name_label;
	private javax.swing.JComboBox cp_paymentTermsCode_combobox;
	private javax.swing.JLabel cp_paymentTermsCode_label;
	private javax.swing.JTextField cp_phoneNum_field1;
	private javax.swing.JTextField cp_phoneNum_field2;
	private javax.swing.JLabel cp_phoneNum_label1;
	private javax.swing.JLabel cp_phoneNum_label2;
	private javax.swing.JComboBox cp_priceSheetTemplate_combobox;
	private javax.swing.JLabel cp_priceSheetTemplate_label;
	private javax.swing.JComboBox cp_priceSheet_combobox;
	private javax.swing.JLabel cp_priceSheet_label;
	private javax.swing.JLabel cp_printPriceSheet_field;
	private javax.swing.JLabel cp_printPriceSheet_label;
	private javax.swing.JCheckBox cp_printStatements_checkbox;
	private javax.swing.JLabel cp_printStatements_label;
	private javax.swing.JButton cp_print_button;
	private javax.swing.JComboBox cp_salesmanCode_combobox;
	private javax.swing.JLabel cp_salesmanCode_label;
	private javax.swing.JButton cp_saveCustChanges_button;
	public javax.swing.JButton cp_selectCustomer_button;
	private javax.swing.JTextField cp_state_field;
	private javax.swing.JLabel cp_state_label;
	private javax.swing.JComboBox cp_taxAreaCode_combobox;
	private javax.swing.JLabel cp_taxAreaCode_label;
	private javax.swing.JComboBox cp_taxExemptionCode_combobox;
	private javax.swing.JLabel cp_taxExemptionCode_label;
	private javax.swing.JCheckBox cp_taxLiable_checkbox;
	private javax.swing.JLabel cp_taxLiable_label;
	private javax.swing.JTextField cp_zipcode_field;
	private javax.swing.JLabel cp_zipcode_label;
	private javax.swing.JDialog custChangesSaved_dialog;
	private javax.swing.JDialog fieldsFail;
	private javax.swing.JScrollPane jScrollPane5;
	private javax.swing.JLabel message;
	private javax.swing.JLabel message2;
	private javax.swing.JDialog selectCust_dialog_CUSTOMER;
	private javax.swing.JButton selectCust_dialog_CUSTOMER_button;
	private javax.swing.JComboBox selectCust_dialog_CUSTOMER_combobox;
	private javax.swing.JLabel selectCust_dialog_CUSTOMER_error;
	private javax.swing.JLabel selectCust_dialog_CUSTOMER_label;
	// End of variables declaration//GEN-END:variables

	//TODO: the start of our code
	////////////////Our variable declarations /////////////////
	//TODO: clean out unnecessary variables out of here
	//CustomersDao CustomersDAO = CustomersDaoFactory.create();
	//	ItemsDao ItemsDAO = ItemsDaoFactory.create();
	//	OrdereditemsDao OrdereditemsDAO = OrdereditemsDaoFactory.create();
	//	OrdersDao OrdersDAO = OrdersDaoFactory.create();

	Mediator MEDIATOR = Mediator.getInstance();

	DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm");
	DecimalFormat decimlPriceFormat = new DecimalFormat("#.##");

	///////////// End of our variable declarations /////////////

	//////////////Final String Declarations ///////////////////////////
	final String EMPTY_CUSTOMER_ID = "000000";
	final String ACTIVATE_CUSTOMER = "Activate Customer";
	final String DEACTIVATE_CUSTOMER = "Deactivate Customer";
	final String ACTIVE = "Active";
	final String INACTIVE = "Inactive";
	
	final String PHONE_EXAMPLE = "e.g. 1234567890";

	///////////// End of our variable declarations /////////////

	// Disables or enables all interactive components in the customer panel
	public void setCustomerPanelComponentsEnabledParameterTo(boolean flag) {

		this.setEnabled(flag);
		this.cp_selectCustomer_button.setEnabled(flag);
		this.cp_priceSheet_combobox.setEnabled(flag);
		this.cp_saveCustChanges_button.setEnabled(flag);
		this.cp_foreman_combobox.setEnabled(flag);
		this.cp_extSalespersonCode_combobox.setEnabled(flag);
		this.cp_salesmanCode_combobox.setEnabled(flag);
		this.cp_interval_field.setEnabled(flag);
		this.cp_priceSheetTemplate_combobox.setEnabled(flag);
		this.cp_paymentTermsCode_combobox.setEnabled(flag);
		this.cp_eachSheetCode_combobox.setEnabled(flag);
		this.cp_billToCustID_combobox.setEnabled(flag);
		this.cp_financeChargeCode_combobox.setEnabled(flag);
		this.cp_taxExemptionCode_combobox.setEnabled(flag);
		this.cp_taxAreaCode_combobox.setEnabled(flag);
		this.cp_custActivation_button.setEnabled(flag);
		if (flag) {
			this.cp_phoneNum_label1.setToolTipText(PHONE_EXAMPLE);
			this.cp_phoneNum_field1.setToolTipText(PHONE_EXAMPLE);
			this.cp_phoneNum_label2.setToolTipText(PHONE_EXAMPLE);
			this.cp_phoneNum_field2.setToolTipText(PHONE_EXAMPLE);
			this.cp_faxNum_label.setToolTipText(PHONE_EXAMPLE);
			this.cp_faxNum_field.setToolTipText(PHONE_EXAMPLE);
		}
		else {
			this.cp_phoneNum_label1.setToolTipText(null);
			this.cp_phoneNum_field1.setToolTipText(null);
			this.cp_phoneNum_label2.setToolTipText(null);
			this.cp_phoneNum_field2.setToolTipText(null);
			this.cp_faxNum_label.setToolTipText(null);
			this.cp_faxNum_field.setToolTipText(null);
		}
	}

	// Updates the Foreman combobox drop-down list accessed from the customer screen.
	private void updateSelectForemanComboboxInCUSTOMER() {
		// Clear the combobox.
		cp_foreman_combobox.removeAllItems();
		// Adds 'Select Foreman'
		cp_foreman_combobox.addItem(SELECT_FOREMAN);
		// Adds all foremans
		ArrayList<Employee> newForemanList = MEDIATOR.getForemanList();
		for (int i = 0; i < newForemanList.size(); i++) {
			cp_foreman_combobox.addItem(newForemanList.get(i).getLastName());
		}
	}

	//	// Updates the Foreman combobox drop-down list accessed from the customer screen.
	private void updateSelectExtSalespersonCodeComboboxInCUSTOMER() {
		// Clear the combobox.
		cp_extSalespersonCode_combobox.removeAllItems();
		// Adds 'Select an External Salesperson'
		cp_extSalespersonCode_combobox.addItem(SELECT_EXTERNAL_SALESPERSON);
		// Adds all External Salesperson
		ArrayList<Employee> newExtSalespersonList = MEDIATOR
				.getExternalSalespersonList();
		for (int i = 0; i < newExtSalespersonList.size(); i++) {
			cp_extSalespersonCode_combobox.addItem(newExtSalespersonList.get(i)
					.getLastName());
		}
	}

	// Updates the Foreman combobox drop-down list accessed from the customer screen.
	private void updateSelectSalespersonCodeComboboxInCUSTOMER() {
		// Clear the combobox.
		cp_salesmanCode_combobox.removeAllItems();
		// Adds 'Select a Salesman'
		cp_salesmanCode_combobox.addItem(SELECT_SALESPERSON);
		// Adds all Salesmen
		ArrayList<Employee> newSalespersonList = MEDIATOR.getSalespersonList();
		for (int i = 0; i < newSalespersonList.size(); i++) {
			cp_salesmanCode_combobox.addItem(newSalespersonList.get(i)
					.getLastName());
		}
	}

	// Updates the Price Sheet Contact Combobox
	private void updatePriceSheetCombobox() {
		cp_priceSheet_combobox.removeAllItems();
		cp_priceSheet_combobox.addItem(SELECT_PRICE_SHEET);
		ArrayList<Pricesheets> newPriceSheetList = MEDIATOR
				.getEditPriceSheets();
		for (int i = 0; i < newPriceSheetList.size(); i++) {
			cp_priceSheet_combobox.addItem(newPriceSheetList.get(i)
					.getPriceSheetName());
		}
	}

	// Updates the Price Group Combobox
	private void updatePriceSheetTemplateCombobox() {
		cp_priceSheetTemplate_combobox.removeAllItems();
		cp_priceSheetTemplate_combobox.addItem(SELECT_PRICE_GROUP);
		ArrayList<Pricesheets> newPriceGroupList = MEDIATOR
				.getPriceSheetTemplates();
		for (int i = 0; i < newPriceGroupList.size(); i++) {
			cp_priceSheetTemplate_combobox.addItem(newPriceGroupList.get(i)
					.getPriceSheetName());
		}
	}

	// Updates teh Bill TO Customer ID Combobox
	private void updateSelectBillToCustomerIDComboboxInCUSTOMER() {
		// Clear the combobox.
		cp_billToCustID_combobox.removeAllItems();
		// Adds 'Select a Salesman'
		cp_billToCustID_combobox.addItem(SELECT_CUSTID);
		cp_billToCustID_combobox.addItem(DEFAULT_BILL_TO_ID);
		// Adds all Salesmen
		int[] newCustomerIDList = MEDIATOR.getCustomerIDList();
		for (int i = 0; i < newCustomerIDList.length; i++) {
			cp_billToCustID_combobox.addItem(newCustomerIDList[i]);
		}
	}

	// Updates the Bill To Customer ID combobox
	private void updateEditBillToCustomerIDComboboxinCUSTOMER(int custID) {
		cp_billToCustID_combobox.removeAllItems();
		cp_billToCustID_combobox.addItem(SELECT_CUSTID);
		ArrayList<Integer> newCustomerIDList = MEDIATOR
				.getCustomerBillToIDList(custID);
		for (int j = 0; j < newCustomerIDList.size(); j++) {
			cp_billToCustID_combobox.addItem(newCustomerIDList.get(j));
		}
	}

	// Fills out customer related fields in the customer screen
	private void fill_Customer_Screen() {

		// Getting the customer index from the screen.
		String aString = cp_custID_field.getText();
		int CustID = Integer.parseInt(aString);

		// custIndex = the customer's index in the Customers array in the mediator
		int custIndex = MEDIATOR.getCustomerEditListNumber(CustID);

		// Checks whether the given customer is active based on its custindex.
		if (MEDIATOR.getIsCustomerActive(custIndex)) {
			cp_custStatus_field.setText(ACTIVE);
			cp_custActivation_button.setText(DEACTIVATE_CUSTOMER);
		} else {
			cp_custStatus_field.setText(INACTIVE);
			cp_custActivation_button.setText(ACTIVATE_CUSTOMER);
		}

		// Sets all fields of the customer screen
		cp_name_field.setText(MEDIATOR.getCustomerEditName(custIndex));
		cp_address_field1.setText(MEDIATOR.getCustomerEditAddress1(custIndex));
		cp_address_field2.setText(MEDIATOR.getCustomerEditAddress2(custIndex));
		cp_city_field.setText(MEDIATOR.getCustomerEditCity(custIndex));
		cp_state_field.setText(MEDIATOR.getCustomerEditState(custIndex));
		cp_zipcode_field.setText(MEDIATOR.getCustomerEditZip(custIndex));
		//TODO: Test this line of code
		cp_directions_field.setText(MEDIATOR
				.getCustomerEditDirections(custIndex));
		cp_phoneNum_field1.setText(MEDIATOR.getCustomerEditPhone1(custIndex));
		cp_phoneNum_field2.setText(MEDIATOR.getCustomerEditPhone2(custIndex));
		cp_faxNum_field.setText(MEDIATOR.getCustomerEditFax(custIndex));
		cp_interval_field.setText(String.valueOf(MEDIATOR
				.getCustomerEditHistoryInterval(custIndex)));
		// Updates the Foreman list and selects the appropriate foreman
		ArrayList<Employee> newForemanList = MEDIATOR.getForemanList();
		String foreman = MEDIATOR.getCustomerEditForeman(custIndex);
		for (int i = 0; i < newForemanList.size(); i++) {
			if (foreman == newForemanList.get(i).getLastName()) {
				cp_foreman_combobox.setSelectedIndex(++i);
			}
		}

		// Updates the Salesperson list and selects the appropriate Salesperson
		ArrayList<Employee> newSalespersonList = MEDIATOR.getSalespersonList();
		String salesperson = MEDIATOR.getCustomerEditSalesperson(custIndex);
		for (int i = 0; i < newSalespersonList.size(); i++) {
			if (salesperson == newSalespersonList.get(i).getLastName()) {
				cp_salesmanCode_combobox.setSelectedIndex(++i);
			}
		}

		//Updates the External Salesperson list and selects the appropriate ext salesperson
		ArrayList<Employee> newExtSalespersonList = MEDIATOR
				.getExternalSalespersonList();
		String extSalesperson = MEDIATOR
				.getCustomerEditExternalSalesperson(custIndex);
		for (int i = 0; i < newExtSalespersonList.size(); i++) {
			if (extSalesperson == newExtSalespersonList.get(i).getLastName()) {
				cp_extSalespersonCode_combobox.setSelectedIndex(++i);
			}
		}

		// Updates the Price Sheet Template list and selects the appropriate price sheet
		ArrayList<Pricesheets> newPriceSheetList = MEDIATOR
				.getEditPriceSheets();
		String priceSheet = MEDIATOR
				.getCustomerEditPriceSheetContact(custIndex);
		for (int i = 0; i < newPriceSheetList.size(); i++) {
			if (priceSheet == newPriceSheetList.get(i).getPriceSheetName()) {
				cp_priceSheet_combobox.setSelectedIndex(++i);
			}
		}

		// Updates the Price Group Code list and selects the appropriate price group
		ArrayList<Pricesheets> newGroupCodeList = MEDIATOR
				.getPriceSheetTemplates();
		String priceGroupCode = MEDIATOR.getCustomerPriceGroupCode(custIndex);
		for (int i = 0; i < newGroupCodeList.size(); i++) {
			if (priceGroupCode == newGroupCodeList.get(i).getPriceSheetName()) {
				cp_priceSheetTemplate_combobox.setSelectedIndex(++i);
			}
		}

		// Updates the Bill to Customer ID list and selects the appropriate Bill to Customer ID
		updateEditBillToCustomerIDComboboxinCUSTOMER(CustID);
		ArrayList<Integer> newCustomerIDList = MEDIATOR
				.getCustomerBillToIDList(CustID);
		int billToCustomerID = MEDIATOR.getCustomerEditBillToID(custIndex);
		if (billToCustomerID != -1) {
			for (int i = 0; i < newCustomerIDList.size(); i++) {
				if (billToCustomerID == newCustomerIDList.get(i)) {
					cp_billToCustID_combobox.setSelectedIndex(++i);
				}
			}
		} else {
			this.message.setText("No Bill-To Customer ID found.");
			this.message2.setText("");
			this.fieldsFail.setVisible(true);
			this.fieldsFail.toFront();
		}
		// Checks if the customer that the bill to ID is matched to is actually active.
		if (!MEDIATOR.checkCustomerBillToID(custIndex)) {
			this.message
					.setText("This Customer has a Bill-To Customer ID that is matched to a customer that is no longer active. Please change this.");
			this.message2.setText("");
			this.fieldsFail.setVisible(true);
			this.fieldsFail.toFront();
		}
		// Checks if the salesperson that the customer is mapped to is active.
		if (!MEDIATOR.checkCustomerEmployeeID(MEDIATOR
				.getCustomerSalesperson(custIndex))) {
			this.message
					.setText("This Customer has a Salesperson code that is matched to an employee that is no longer active. Please change this.");
			this.message2.setText("");
			this.fieldsFail.setVisible(true);
			this.fieldsFail.toFront();
		}
		// Checks if the external salesperson that the customer is mapped to is active.
		if (!MEDIATOR.checkCustomerEmployeeID(MEDIATOR
				.getCustomerExternalSalesperson(custIndex))) {
			this.message
					.setText("This Customer has an External Salesperson code that is matched to an employee that is no longer active. Please change this.");
			this.message2.setText("");
			this.fieldsFail.setVisible(true);
			this.fieldsFail.toFront();
		}
		// Checks if the foreman that the customer is mapped to is active.
		if (!MEDIATOR.checkCustomerEmployeeID(MEDIATOR
				.getCustomerForeman(custIndex))) {
			this.message
					.setText("This Customer has a Foreman code that is matched to an employee that is no longer active. Please change this.");
			this.message2.setText("");
			this.fieldsFail.setVisible(true);
			this.fieldsFail.toFront();
		}

	}

	// Updates the combobox drop-down list accessed from customer screen
	public void updateSelectCustomerComboboxInCUSTOMER() {
		// Clears the combobox
		selectCust_dialog_CUSTOMER_combobox.removeAllItems();
		// Adds 'Select a customer...' to the top of the list
		selectCust_dialog_CUSTOMER_combobox.addItem("Select a customer...");
		// Adds all the customers to the list
		String[] newCustList = MEDIATOR.getCustomerEditNames();
		for (int i = 0; i < newCustList.length; i++) {
			selectCust_dialog_CUSTOMER_combobox.addItem(newCustList[i]);
		}
	}

	public void setNewCustomer() {
		cp_custID_field.setText(EMPTY_CUSTOMER_ID);
		cp_name_field.setText("");
		cp_custStatus_field.setText(ACTIVE);
		cp_custActivation_button.setText(DEACTIVATE_CUSTOMER);
		cp_address_field1.setText("");
		cp_address_field2.setText("");
		cp_city_field.setText("");
		cp_state_field.setText("");
		cp_zipcode_field.setText("");
		cp_directions_field.setText("");
		cp_phoneNum_field1.setText("");
		cp_phoneNum_field2.setText("");
		cp_faxNum_field.setText("");
		cp_interval_field.setText("");
		updateSelectForemanComboboxInCUSTOMER();
		updateSelectExtSalespersonCodeComboboxInCUSTOMER();
		updateSelectSalespersonCodeComboboxInCUSTOMER();
		updateSelectBillToCustomerIDComboboxInCUSTOMER();
		updatePriceSheetCombobox();
		updatePriceSheetTemplateCombobox();
		setUnusedCustomerFieldsInvisible();
	}

	public void showSelectCustDialog(boolean visible) {
		selectCust_dialog_CUSTOMER.setVisible(visible);
	}

	public void setUnusedCustomerFieldsInvisible() {
		// Setting unused Customer fields to invisible.
		//cp_priceSheetContact_label.setVisible(false);
		//cp_priceSheetContact_combobox.setVisible(false);
		//cp_interval_combobox.setVisible(false);
		//cp_interval_label.setVisible(false);
		//cp_priceGroupCode_label.setVisible(false);
		//cp_priceGroupCode_combobox.setVisible(false);
		cp_printPriceSheet_label.setVisible(false);
		cp_printPriceSheet_field.setVisible(false);
		cp_paymentTermsCode_label.setVisible(false);
		cp_paymentTermsCode_combobox.setVisible(false);
		cp_eachSheetCode_label.setVisible(false);
		cp_eachSheetCode_combobox.setVisible(false);
		cp_marriett_label.setVisible(false);
		cp_marriett_field.setVisible(false);
		cp_accountRep_label.setVisible(false);
		cp_accountRep_field.setVisible(false);
		//cp_billToCustID_label.setVisible(false);
		//cp_billToCustID_combobox.setVisible(false);
		cp_financeChargeCode_label.setVisible(false);
		cp_financeChargeCode_combobox.setVisible(false);
		cp_printStatements_label.setVisible(false);
		cp_printStatements_checkbox.setVisible(false);
		cp_taxLiable_label.setVisible(false);
		cp_taxLiable_checkbox.setVisible(false);
		cp_taxExemptionCode_label.setVisible(false);
		cp_taxExemptionCode_combobox.setVisible(false);
		cp_taxAreaCode_label.setVisible(false);
		cp_taxAreaCode_combobox.setVisible(false);
	}

	private Component componentToBePrinted;

	public void print() {
		componentToBePrinted = this;

		PrinterJob printJob = PrinterJob.getPrinterJob();
		printJob.setPrintable(this);
		if (printJob.printDialog())
			try {
				System.out.println("Calling PrintJob.print()");
				printJob.print();
				System.out.println("End PrintJob.print()");
			} catch (PrinterException pe) {
				System.out.println("Error printing: " + pe);
			}
	}

	public int print(Graphics g, PageFormat pf, int pageIndex) {
		int response = NO_SUCH_PAGE;

		Graphics2D g2 = (Graphics2D) g;

		//  for faster printing, turn off double buffering
		disableDoubleBuffering(componentToBePrinted);

		Dimension d = componentToBePrinted.getSize(); //get size of document
		double panelWidth = d.width; //width in pixels
		double panelHeight = d.height; //height in pixels

		double pageHeight = pf.getImageableHeight(); //height of printer page
		double pageWidth = pf.getImageableWidth(); //width of printer page

		double scale = pageWidth / panelWidth;
		int totalNumPages = (int) Math.ceil(scale * panelHeight / pageHeight);

		//  make sure not print empty pages
		if (pageIndex >= totalNumPages) {
			response = NO_SUCH_PAGE;
		} else {

			//  shift Graphic to line up with beginning of print-imageable region
			g2.translate(pf.getImageableX(), pf.getImageableY());

			//  shift Graphic to line up with beginning of next page to print
			g2.translate(0f, -pageIndex * pageHeight);

			//  scale the page so the width fits...
			g2.scale(scale, scale);

			componentToBePrinted.paint(g2); //repaint the page for printing

			enableDoubleBuffering(componentToBePrinted);
			response = Printable.PAGE_EXISTS;
		}
		return response;
	}

	public static void disableDoubleBuffering(Component c) {
		RepaintManager currentManager = RepaintManager.currentManager(c);
		currentManager.setDoubleBufferingEnabled(false);
	}

	public static void enableDoubleBuffering(Component c) {
		RepaintManager currentManager = RepaintManager.currentManager(c);
		currentManager.setDoubleBufferingEnabled(true);
	}
}